/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.xgb.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.xgb.entity.XgbReal;
import com.zcm.modules.xgb.service.XgbRealService;

/**
 * XgbRealController
 * @author www
 * @version 2018-10-07
 */
@Controller
@RequestMapping(value = "${adminPath}/xgb/xgbReal")
public class XgbRealController extends BaseController {

	@Autowired
	private XgbRealService xgbRealService;
	
	@ModelAttribute
	public XgbReal get(@RequestParam(required=false) String id) {
		XgbReal entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = xgbRealService.get(id);
		}
		if (entity == null){
			entity = new XgbReal();
		}
		return entity;
	}
	
	@RequiresPermissions("xgb:xgbReal:view")
	@RequestMapping(value = {"list", ""})
	public String list(XgbReal xgbReal, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<XgbReal> page = xgbRealService.findPage(new Page<XgbReal>(request, response), xgbReal); 
		model.addAttribute("page", page);
		return "modules/xgb/xgbRealList";
	}

	@RequiresPermissions("xgb:xgbReal:view")
	@RequestMapping(value = "form")
	public String form(XgbReal xgbReal, Model model) {
		model.addAttribute("xgbReal", xgbReal);
		return "modules/xgb/xgbRealForm";
	}

	@RequiresPermissions("xgb:xgbReal:edit")
	@RequestMapping(value = "save")
	public String save(XgbReal xgbReal, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, xgbReal)){
			return form(xgbReal, model);
		}
		xgbRealService.save(xgbReal);
		addMessage(redirectAttributes, "保存XgbReal成功");
		return "redirect:"+Global.getAdminPath()+"/xgb/xgbReal/?repage";
	}
	
	@RequiresPermissions("xgb:xgbReal:edit")
	@RequestMapping(value = "delete")
	public String delete(XgbReal xgbReal, RedirectAttributes redirectAttributes) {
		xgbRealService.delete(xgbReal);
		addMessage(redirectAttributes, "删除XgbReal成功");
		return "redirect:"+Global.getAdminPath()+"/xgb/xgbReal/?repage";
	}

}